package com.report.service;

import cn.dev33.satoken.session.SaSession;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import cn.zhxu.bs.BeanSearcher;
import cn.zhxu.bs.util.MapBuilder;
import cn.zhxu.bs.util.MapUtils;
import com.report.dto.response.LogRes;
import com.report.dto.response.MemberRes;
import com.zmh.framework.util.Result;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author summer
 * @version 1.0
 * @date 2024/9/2 15:22
 */
@Service
@AllArgsConstructor
public class ActiveUserService {

    private final BeanSearcher beanSearcher;

    public  List<LogRes>  lists(){
         MapBuilder builder = MapUtils.builder();
        List<String> logIds = StpUtil.searchSessionId("", 0, -1, false);
        logIds.forEach(log->{
            SaSession sessionBySessionId = StpUtil.getSessionBySessionId(log);

        });
        Set<LogRes> set=new HashSet<>();
        List<String> strings = StpUtil.searchTokenValue("", 0, 1000, true);
        strings.forEach(token->{
           String tokenValue= StrUtil.subAfter(token, "Authorization:login:token:", true);
           Object loginIdByToken = StpUtil.getLoginIdByToken(tokenValue);
           builder.field(LogRes::getMemberId,loginIdByToken);
           LogRes logRes = beanSearcher.searchFirst(LogRes.class, builder.build());
            set.add(logRes);
        });
        return ListUtil.toList(set);
    }
}
